Skip to content

Conversation

multiplemonomials
Copy link
Collaborator

@multiplemonomials multiplemonomials commented Sep 6, 2025

Summary of changes

This PR implements very basic support for using Mbed OS CE as a PlatformIO framework.

The bulk of of the work here is in implementing a script that will load the target information created by CMake and pass it to SCons, PlatformIO's build system. Luckily, some PIO devs pointed out that someone else had already done this for ESP-IDF, which also uses CMake. I used this script as a base, but also made a number of improvements:

  • Split it into two files, cmake_to_scons_converter.py which contains the non-Mbed-CE-specific logic for converting CMake API data to SCons format, and build_mbed_ce.py which is a PlatformIO-SCons script for Mbed CE.
  • Add documentation and type annotations to many functions
  • Upgrade everything to use pathlib.Path
  • Instead of reimplementing the linker script generation logic in SCons, just call it from the configure script as it is quick to do.
  • Don't require the PIO project to have a CMakeLists.txt. Instead, just use a constant CMakeLists.txt bundled with the Python package. This makes the usage of CMake completely opaque to the PIO developer.

With these changes, and a patched platform repo, and a patched PIO core library (5 line change), it is possible to build and use Mbed CE with PlatformIO.

Also, I put some effort into making sure that rebuilds/reconfigures are done when needed. I have made sure that:

  • Changing the build type pio run vs pio debug causes a rebuild with the correct flags
  • Modifying mbed_app.json causes a reconfigure and a rebuild of all sources

Note that since this has only basic platformIO support, it does not yet support linking libraries other than mbed-os. This means you cannot use mbed-baremetal or other libraries like netsocket.

Impact of changes

Mbed CE can be used as a PlatformIO framework

Migration actions required

Documentation

None yet but will work with PlatformIO developers


Pull request type

[] Patch update (Bug fix / Target update / Docs update / Test update / Refactor)
[X] Feature update (New feature / Functionality change / New API)
[] Major update (Breaking change E.g. Return code change / API behaviour change)

Test results

[] No Tests required for this change (E.g docs only update)
[] Covered by existing mbed-os tests (Greentea or Unittest)
[X] Tests / results supplied as part of this PR

Able to flash and run code on my K64F board using this branch!

@multiplemonomials multiplemonomials changed the title [draft] Implement support for building Mbed as a PlatformIO framework Implement support for building Mbed as a PlatformIO framework Sep 15, 2025
@multiplemonomials multiplemonomials merged commit aeb3ed8 into master Sep 19, 2025
53 checks passed
@multiplemonomials multiplemonomials deleted the dev/platformio branch September 19, 2025 08:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants